package com.quad.innovators.salesease.controller.warehouse;

import com.quad.innovators.salesease.annotation.Log;
import com.quad.innovators.salesease.common.result.Result;
import com.quad.innovators.salesease.constants.SystemConstants;
import com.quad.innovators.salesease.enums.LogModuleEnum;
import com.quad.innovators.salesease.model.form.warehouse.VehicleBringScanCodeForm;
import com.quad.innovators.salesease.service.warehouse.VehicleBringScanCodeService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

/**
 * @author : shanshan.li
 * @createTime : 2025/4/20 11:45
 * @Version : 1.0 
 */
@Tag(name = "18.车辆带货扫码")
@RestController
@RequestMapping(SystemConstants.BACKEND_API + "/vehicle-bring-goods-scan")
@RequiredArgsConstructor
public class VehicleBringGoodsScanController {
    private final VehicleBringScanCodeService vehicleBringScanCodeService;

    @Operation(summary = "新增扫码信息")
    @PostMapping("")
    @Log(value = "新增扫码信息", module = LogModuleEnum.VEHICLE_BRING_GOODS)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<?> save(VehicleBringScanCodeForm form) {
        String result = vehicleBringScanCodeService.save(form);
        return Result.success(result);
    }

    @Operation(summary = "删除扫码信息")
    @DeleteMapping("/{code}")
    @Log(value = "删除扫码信息", module = LogModuleEnum.VEHICLE_BRING_GOODS)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<?> delete(@PathVariable("code") String code) {
        boolean result = vehicleBringScanCodeService.delete(code);
        return Result.success(result);
    }

    @Operation(summary = "获取扫码列表")
    @GetMapping("/{vehicleBringGoodsCode}/list")
    @Log(value = "获取扫码列表", module = LogModuleEnum.VEHICLE_BRING_GOODS)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<List<VehicleBringScanCodeForm>> getList(@PathVariable("vehicleBringGoodsCode") String vehicleBringGoodsCode, @RequestParam("scanType") Integer scanType) {
        return Result.success(vehicleBringScanCodeService.getListByVehicleCode(vehicleBringGoodsCode, scanType));
    }

    @Operation(summary = "获取扫码详情")
    @GetMapping("/{code}")
    @Log(value = "获取扫码详情", module = LogModuleEnum.VEHICLE_BRING_GOODS)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<VehicleBringScanCodeForm> getDetail(@PathVariable("code") String code) {
        return Result.success(vehicleBringScanCodeService.getDetail(code));
    }


}